package com.gdufe.studytogether.utils;

public class UserThreadLocal {
  private UserThreadLocal(){}
  //线程变量隔离
  private static final ThreadLocal<Integer> LOCAL = new ThreadLocal<>();

  public static void put(Integer userId){
    LOCAL.set(userId);
  }

  public static Integer get() throws Exception {
    Integer integer = LOCAL.get();
    if (integer==null){
      throw new Exception("未登录");
    }
    return integer;
  }

  public static void remove(){
    LOCAL.remove();
  }
}
